package org.mdrtwell.common;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Digest {
	public MD5Digest() {
	}

	public String digest(String pass) {
		MessageDigest alga = null;
		try {
			alga = java.security.MessageDigest.getInstance("MD5");
		} catch (NoSuchAlgorithmException ex) {
			ex.printStackTrace();
		}
		alga.update(pass.getBytes());
		byte[] digesta = alga.digest();
		return byte2hex(digesta);
	}

	public String byte2hex(byte[] b) {
		String hs = "";
		String stmp = "";
		for (int n = 0; n < b.length; n++) {
			stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
			if (stmp.length() == 1) {
				hs = hs + "0" + stmp;
			} else {
				hs = hs + stmp;
			}
		}
		return hs.toLowerCase();
	}

	public static void main(String[] args) {
		MD5Digest test = new MD5Digest();
		System.out.println(test.digest("11111111"));
	}
}
